package com.jungle.client.demo;
import com.github.benmanes.caffeine.cache.Cache;
import com.github.benmanes.caffeine.cache.Caffeine;

import java.util.concurrent.TimeUnit;

public class DataService {
    public Cache<String, Object> caffeineCache() {
        return Caffeine.newBuilder()
                .initialCapacity(100)
                .maximumSize(1000)
                .expireAfterWrite(10, TimeUnit.MINUTES)
                .build();
    }

    public static void main(String[] args) {
        DataService dataService = new DataService();
        Cache<String, Object> cache = dataService.caffeineCache();
        cache.put("key", "value");
        System.out.println(cache.getIfPresent("key"));
        cache.invalidate("key");
        System.out.println(cache.getIfPresent("key"));
    }
}
